/**
 * @description  深度克隆
 * @param obj    任意数据
 * @returns
 */
export function deepClone(obj: any) {
  // 检查输入是否为对象类型
  if (typeof obj !== "object" || obj === null) {
    return obj;
  }

  // 创建新的对象或数组
  let cloneVal: any;
  if (Array.isArray(obj)) {
    cloneVal = [];
  } else {
    cloneVal = {};
  }

  // 遍历对象/数组的每个属性/元素并递归克隆
  // for in深拷贝
  //   for (let key in obj) {
  //     if (obj.hasOwnProperty(key)) {
  //       clone[key] = deepClone(obj[key]);
  //     }
  //   }

  // for of深拷贝
  for (const values of Object.entries(obj)) {
    if (obj.hasOwnProperty(values[0])) {
      cloneVal[values[0]] = deepClone(values[1]);
    }
  }
  return cloneVal;
}

/**
 * @description  获取当前年龄
 * @param birth
 * @returns
 */
export const getAge = (birth: any) => {
  console.log(birth);

  if (birth) {
    let birthday = new Date(birth);
    let now = new Date().getTime();
    let hours = (now - birthday) / 3600000;
    let year = Math.floor(hours / (24 * 30 * 12));
    return year;
  } else {
    return 0;
  }
};
